import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class Matrix {


    public static void main(String[] args) {

//        int w = 10;
//        int h = 10;
//
//        int[][] mat = printMatrix2(w,h);
//
//        for(int i = 0 ;i < h ; ++i){
//            for(int j = 0 ; j < w ; ++j){
//
//                System.out.print(mat[i][j] + " ");
//
//                if(mat[i][j] < 10){
//
//                    System.out.print("    ");
//                }
//                else if(mat[i][j] < 100){
//                    System.out.print("   ");
//                }
//                else if(mat[i][j] < 1000){
//                    System.out.print("  ");
//                }
//                else if(mat[i][j] < 1000){
//                    System.out.print(" ");
//                }
//
//
//            }
//
//            System.out.println();
//        }

        //priteNun();


    }





    public static void priteNun(){
        int m=21 ;
        int n=-1;
        for(int i=1;i<11;i++){
            m=m-2;
            n=n+2;
            boolean flag=true;
            int tem=i;
            for(int j=0;j<10;j++){
                if(flag){
                    System.out.print(tem + " ");
                    flag=false;
                }else{
                    if(j%2==1){
                        tem=tem+m;
                        System.out.print(tem+" ");
                    }

                    else if(j%2==0) {
                        tem = tem + n;
                        System.out.print(tem+" ");
                    }
                }

                if(tem < 10){
                    System.out.print("    ");
                }
                else{
                    System.out.print("   ");
                }

            }
            System.out.println();
        }


    }


    public static int[][] printMatrix2(int w ,int h){

        Matrix matrix = new Matrix();

        int[][] mat = new int[h][w];

        int x = 0;
        int y = 0;
        int index = 1;
        int di = 0;

        for(;;){
            mat[y][x] = index;
            int tmpx = x + matrix.directions.get(di).getX();
            int tmpy = y + matrix.directions.get(di).getY();

            if(index == w*h){
                break;
            }
            if( tmpx >= w || tmpy >= h || tmpx < 0 || tmpy < 0){
                di = (di + 1) % 4;
            }
            else if(mat[tmpy][tmpx] > 0){
                di = (di + 1) % 4;
            }
            else{
                x = tmpx;
                y = tmpy;
                ++index;
            }
        }

        return mat;
    }

    public List<Direction> directions = new ArrayList<Direction>(){
        {
            add(new Direction(1,0));
            add(new Direction(0,1));
            add(new Direction(-1,0));
            add(new Direction(0,-1));
        }

    };

    public class Direction{
        int x;
        int y;

        public int getX() {
            return x;
        }

        public void setX(int x) {
            this.x = x;
        }

        public int getY() {
            return y;
        }

        public void setY(int y) {
            this.y = y;
        }

        public Direction(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

}
